﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure.Aspect.Extensions;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Presentation.Regions;
using Microsoft.Practices.Composite.Regions;
namespace Infrastructure.WpfClient.Services.Navigation
{
    public class NavigationService : INavigationService
    {
        private RegionManager regionManager;
        private IUnityContainer ContainerService;
        public NavigationService(IUnityContainer container)
        {
            this.regionManager = container.Resolve<RegionManager>();
            this.ContainerService = container.Resolve<IUnityContainer>();
        }
        public IView Navigate<IView>(string WorkSpaceName)
        {            
            var view = this.ContainerService.Resolve<IView>();
            Navigate<IView>(view,WorkSpaceName);
            return view;
        }
        public void Navigate<IView>(IView view, string WorkSpaceName)
        {            
                this.regionManager.AddToRegion(WorkSpaceName, view);
                this.regionManager.Regions[WorkSpaceName].Activate(view);
        }
        public void Navigate(Uri NavigationUri)
        {
            this.regionManager.AddToRegion(Infrastructure.WpfClient.Constants.RegionNames.FrameWorkspace, NavigationUri);
            this.regionManager.Regions[Infrastructure.WpfClient.Constants.RegionNames.FrameWorkspace].Activate(NavigationUri);
        }       
    }
}
